# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.

if Rails.env.production?
  secrets = Gitlab::Email::SmtpConfig.secrets
  smtp_settings = {
    <% unless @smtp_authentication.nil? %>
    authentication: <%= @smtp_authentication.to_s.to_sym.inspect %>,
    <% end %>
    user_name: <%= node['gitlab']['gitlab_rails']["smtp_user_name"]&.inspect || "secrets.username" %>,
    password: <%= node['gitlab']['gitlab_rails']["smtp_password"]&.inspect || "secrets.password"  %>,
<% %w{ address port domain enable_starttls_auto tls ssl openssl_verify_mode ca_path ca_file open_timeout read_timeout }.each do |key| %>
  <% value = node['gitlab']['gitlab_rails']["smtp_#{key}"] %>
    <%= "#{key}: #{value.inspect}," unless value.nil? %>
<% end %>
  }

<% if @smtp_pool %>
  require 'mail/smtp_pool'

  ActionMailer::Base.add_delivery_method :smtp_pool, Mail::SMTPPool

  Gitlab::Application.config.action_mailer.delivery_method = :smtp_pool
  ActionMailer::Base.delivery_method = :smtp_pool

  ActionMailer::Base.smtp_pool_settings = {
    pool: Mail::SMTPPool.create_pool(
      smtp_settings.merge(pool_size: Gitlab::Runtime.max_threads)
    )
  }
<% else %>
  Gitlab::Application.config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.delivery_method = :smtp

  ActionMailer::Base.smtp_settings = smtp_settings
<% end %>
end
